// src/main/java/com/fjnu/dao/impl/CategoryDaoImpl.java
package com.fjnu.dao.impl;

import com.fjnu.dao.CategoryDao;
import com.fjnu.entity.Category;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.Date;

public class CategoryDaoImpl implements CategoryDao {
    private JdbcTemplate jdbcTemplate;
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
    @Override
    public int insert(Category category) {
        String sql = "INSERT INTO tb_category(name, `order`, parent_id, create_time, update_time) " +
                "VALUES(?, ?, ?, ?, ?)";
        return jdbcTemplate.update(sql, category.getName(), category.getOrder(),
                category.getParentId(), new Date(), new Date());
    }
    @Override
    public int delete(Integer categoryId) {
        String sql = "DELETE FROM tb_category WHERE id = ?";
        return jdbcTemplate.update(sql, categoryId);
    }
}